package main.java.com.healthy.entity;

import java.io.Serializable;

/**
 * 食物实体类
 * 对应功能模块：食物营养数据库模块
 */
public class Food implements Serializable {
    private static final long serialVersionUID = 1L;

    private String foodId;
    private String foodName;
    private String category; // 食物类别：主食、蔬菜、水果、肉类、蛋类、乳制品、豆制品、坚果、饮料等
    private double calories; // 每100g热量(千卡)
    private double carbohydrates; // 每100g碳水化合物(g)
    private double protein; // 每100g蛋白质(g)
    private double fat; // 每100g脂肪(g)
    private double fiber; // 每100g膳食纤维(g)
    private double sugar; // 每100g糖分(g)
    private double sodium; // 每100g钠含量(mg)
    private String description; // 食物描述
    private boolean isCustom; // 是否为用户自定义食物

    // 默认构造方法
    public Food() {}

    // 主要参数构造方法
    public Food(String foodId, String foodName, String category, double calories,
                double carbohydrates, double protein, double fat) {
        this.foodId = foodId;
        this.foodName = foodName;
        this.category = category;
        this.calories = calories;
        this.carbohydrates = carbohydrates;
        this.protein = protein;
        this.fat = fat;
    }

    // 完整参数构造方法
    public Food(String foodId, String foodName, String category, double calories,
                double carbohydrates, double protein, double fat, double fiber,
                double sugar, double sodium, String description, boolean isCustom) {
        this.foodId = foodId;
        this.foodName = foodName;
        this.category = category;
        this.calories = calories;
        this.carbohydrates = carbohydrates;
        this.protein = protein;
        this.fat = fat;
        this.fiber = fiber;
        this.sugar = sugar;
        this.sodium = sodium;
        this.description = description;
        this.isCustom = isCustom;
    }

    // Getter和Setter方法
    public String getFoodId() {
        return foodId;
    }

    public void setFoodId(String foodId) {
        this.foodId = foodId;
    }

    public String getFoodName() {
        return foodName;
    }

    public void setFoodName(String foodName) {
        this.foodName = foodName;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public double getCalories() {
        return calories;
    }

    public void setCalories(double calories) {
        this.calories = calories;
    }

    public double getCarbohydrates() {
        return carbohydrates;
    }

    public void setCarbohydrates(double carbohydrates) {
        this.carbohydrates = carbohydrates;
    }

    public double getProtein() {
        return protein;
    }

    public void setProtein(double protein) {
        this.protein = protein;
    }

    public double getFat() {
        return fat;
    }

    public void setFat(double fat) {
        this.fat = fat;
    }

    public double getFiber() {
        return fiber;
    }

    public void setFiber(double fiber) {
        this.fiber = fiber;
    }

    public double getSugar() {
        return sugar;
    }

    public void setSugar(double sugar) {
        this.sugar = sugar;
    }

    public double getSodium() {
        return sodium;
    }

    public void setSodium(double sodium) {
        this.sodium = sodium;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean isCustom() {
        return isCustom;
    }

    public void setCustom(boolean custom) {
        isCustom = custom;
    }

    // 计算指定重量的营养成分
    public double calculateCalories(double weight) {
        return calories * weight / 100;
    }

    public double calculateCarbohydrates(double weight) {
        return carbohydrates * weight / 100;
    }

    public double calculateProtein(double weight) {
        return protein * weight / 100;
    }

    public double calculateFat(double weight) {
        return fat * weight / 100;
    }

    public double calculateFiber(double weight) {
        return fiber * weight / 100;
    }

    // 获取能量来源比例
    public double getCarbPercentage() {
        double totalEnergy = carbohydrates * 4 + protein * 4 + fat * 9;
        return totalEnergy > 0 ? (carbohydrates * 4) / totalEnergy * 100 : 0;
    }

    public double getProteinPercentage() {
        double totalEnergy = carbohydrates * 4 + protein * 4 + fat * 9;
        return totalEnergy > 0 ? (protein * 4) / totalEnergy * 100 : 0;
    }

    public double getFatPercentage() {
        double totalEnergy = carbohydrates * 4 + protein * 4 + fat * 9;
        return totalEnergy > 0 ? (fat * 9) / totalEnergy * 100 : 0;
    }

    @Override
    public String toString() {
        return "Food{" +
                "foodId='" + foodId + '\'' +
                ", foodName='" + foodName + '\'' +
                ", category='" + category + '\'' +
                ", calories=" + calories +
                ", carbohydrates=" + carbohydrates +
                ", protein=" + protein +
                ", fat=" + fat +
                ", fiber=" + fiber +
                ", sugar=" + sugar +
                ", sodium=" + sodium +
                ", isCustom=" + isCustom +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Food food = (Food) o;
        return foodId.equals(food.foodId);
    }

    @Override
    public int hashCode() {
        return foodId.hashCode();
    }
}